$(function () {
    init_phoneNum();
    /**初始化部门**/
    $.post(ctx+"dept/list",{},function (r) {
        $("#phoneDept").empty().append("<option value=''>请选择部门</option>");
        $.each(r,function (index,val) {
            $("#phoneDept").append("<option value='"+val.deptId+"'>"+val.deptName+"</option>");
        });
    });
    init_table();
});
/**切换部门**/
function changeSelectDept(){
    var deptid = $("#phoneDept").val();
    if (deptid !=""){
        $.post(ctx+"user/selectUserByDept",{deptId:deptid},function (r) {
            $("#phoneUsers").empty().append("<option value=''>请选择员工</option>");
            $.each(r,function (index,val) {
                $("#phoneUsers").append("<option value='"+val.userUuid+"'>"+val.nickname+"</option>");
            });
        });
    }else{
        $("#phoneUsers").empty().append("<option value=''>请选择员工</option>");
    }
}
/**初始化部门分配数量**/
function init_phoneNum() {
    var myChart = echarts.init(document.getElementById('InphoneNum'));
    var option = {
        title: {
            text: '本周外接电话统计图'
        },
        tooltip: {
            trigger: 'axis',
            formatter: function (params) {
                /**联动下面的表格**/
                params = params[0];
                return params.name+": "+params.value;
            },
            axisPointer: {
                animation: false
            }
        },
        legend: {},
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {},
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['周一','周二','周三','周四','周五','周六','周日']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name:'外接电话统计',
                type:'line',
                stack: '总量',
                data:[120, 132, 101, 134, 90, 230, 210]
            }
        ]
    };
    myChart.on('mouseover', function (params) {
        console.log(params);
    });
    myChart.setOption(option);
}
/**初始化表格数据**/
function init_table() {
    var settings = {
        url: ctx + "saleDydisRecord/getAllDydiaRecord",
        queryParams: function(params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
            };
        },
        columns: [{
            field: 'sDiaTime',
            title: '接入时间',
            class:'text-center'
        }, {
            field: 'sDiaUname',
            class:'text-center',
            title: '接入客户端'
        }, {
            field: 'sDiaNum',
            class:'text-center',
            title: '电话号码'
        }, {
            field: 'sDiaUrl',
            class:'text-center',
            title: '录音',
            formatter:function (value, row, index) {
                if (value!=null){
                    return "<button type='button' class='btn btn-xs btn-link' data-url="+value+" onclick='playVoid(this);'> 播放录音</button>";
                }
                return "未产生录音";
            }
        }]
        /**
         * , {
            field: 'sDiaUrlTime',
            class:'text-center',
            title: '通话时长',
            formatter:function (value, row, index) {
                var falure = row.sDiaUrlTime;
                return falure+"秒";
            }
        }**/
    };
    $JuXue.initTable('inphoneTable', settings);
}
/**播放录音**/
function playVoid(btn){
   var dataurl = $(btn).attr("data-url");
    $(btn).parent().empty().append("<audio class='height-30' src='myCustomer/imageView1?url="+dataurl+"' controlsList='nodownload' controls='controls' type='audio/wav'></audio>")
}



